﻿using System;
using DataAccess;
using IDataCenterContract;

namespace DataCenterService
{
    public class BaseService
    {
        public BaseService()
        {
            if(string.IsNullOrEmpty(PersistenceProperty.ConnectionString))
            {
            PersistenceProperty.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["DbConnection"]; 
            PersistenceProperty.DatabaseType = (DatabaseType)Enum.Parse(typeof(DatabaseType),System.Configuration.ConfigurationManager.AppSettings["DbType"]);
            }
        }
    }
    public class FunctionLogService :BaseService,IFunctionLogContract
    {
       
        #region IFunctionLogContract 成员

        public void WriteFunctionLog(FunctionLogEntity entity)
        {
            IDataAccess dataaccess = DataAccessFactory.Instance.CreateDataAccess();
            dataaccess.Open();
            try
            {
                const string sql = @"insert into FunctionLog(ID,FunctionName,MacAddress,IP,CurrentTime)
                                values(@ID,@FunctionName,@MacAddress,@IP,@CurrentTime)";
                QueryParameterCollection qpc = new QueryParameterCollection
                                                               {
                                                                   {"@ID", Guid.NewGuid().ToString()},
                                                                   {"@FunctionName", entity.FunctionName},
                                                                   {"@MacAddress", entity.MAC},
                                                                   {"@IP", entity.IP},
                                                                   {"@CurrentTime", DateTime.Now}
                                                               };

                dataaccess.ExecuteNonQuery(sql, qpc);
            }
            catch { }
            finally
            {
                dataaccess.Close();
            }
        }

        #endregion
    }
}
